package com.monitor.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.monitor.entity.ErpSaleParameter;
import com.monitor.service.ErpSaleParameterService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器  维修参数
 * </p>
 *
 * @author LX
 * @since 2018-09-25
 */
@RestController
@RequestMapping("/erpSaleParameter")
@Api(description="维修参数")
public class ErpSaleParameterController {

    @Resource
    private ErpSaleParameterService parameterService;


    @RequestMapping("/inertOrUpdateParameterCustomer")
    @ApiOperation("添加Or修改维修参数信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Integer> inertOrUpdateParameterCustomer(ErpSaleParameter Parameter) {
        Result<Integer> result=new Result<Integer>();
        try{
            if (Parameter.isAddOrXiuGai()==false){
                ErpSaleParameter erpSaleParameter = parameterService.selectById(Parameter.getId());
                Parameter.setZid(erpSaleParameter.getZid());
                result.setData( parameterService.updateById(Parameter)?1:0);
            }else {
                result.setData(parameterService.insert(Parameter)?1:0);
            }
            result.setCount(1);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getParameterCustomerById")
    @ApiOperation("根据维修参数id查询维修参数信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "ParameterId", value = "维修参数ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<ErpSaleParameter> getParameterCustomerById(Integer ParameterId) {
        Result<ErpSaleParameter> result=new Result<ErpSaleParameter>();
        try{
            result.setCount(1);
            result.setData(parameterService.selectById(ParameterId));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/removeParameterCustomerById")
    @ApiOperation("根据维修参数id删除维修参数信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "ParameterId", value = "维修参数ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> removeParameterCustomerById(Integer ParameterId) {
        Result<Integer> result=new Result<Integer>();
        try{
            result.setCount(1);
            result.setData(parameterService.deleteById(ParameterId)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getParameterCustomerByParameterIdPage")
    @ApiOperation("根据维修参数ID查询维修参数分页")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "ParameterId", value = "合同ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Page<ErpSaleParameter>> getParameterCustomerBycustIdPage(@RequestParam(value = "page", defaultValue = "1") int page,
                                                        @RequestParam(value="limit",defaultValue="10") int limit) {
        Result<Page<ErpSaleParameter>> result=new Result<Page<ErpSaleParameter>>();
        try{
            Page<ErpSaleParameter> page1=new Page<ErpSaleParameter>(page,limit);
            Page<ErpSaleParameter> carPage=parameterService.selectPage(page1,new EntityWrapper<ErpSaleParameter>());
            result.setCount(carPage.getRecords().size());
            result.setData(carPage);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getParameterCustomerByParameterIdList")
    @ApiOperation("查询所有维修参数")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "ParameterId", value = "合同ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<List<ErpSaleParameter>> getParameterCustomerBycustIdList() {
        Result<List<ErpSaleParameter>> result=new Result<List<ErpSaleParameter>>();
        try{
            List<ErpSaleParameter> carPage=parameterService.getParameterCustomerBycustIdList();
            result.setCount(carPage.size());
            result.setData(carPage);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }


    @RequestMapping("/getParameterCustomerByParameterIdListOne")
    @ApiOperation("查询所有第一排维修参数")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "ParameterId", value = "合同ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<List<ErpSaleParameter>> getParameterCustomerByParameterIdListOne() {
        Result<List<ErpSaleParameter>> result=new Result<List<ErpSaleParameter>>();
        try{
            List<ErpSaleParameter> carPage=parameterService.selectList(new EntityWrapper<ErpSaleParameter>().eq("pid",0));
            result.setCount(carPage.size());
            result.setData(carPage);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getParameteByParameterId")
    @ApiOperation("查询维修参数id查询下一级")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "parameterId", value = "参数ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpSaleParameter>> getParameteByParameterId(Integer id) {
        Result<List<ErpSaleParameter>> result=new Result<List<ErpSaleParameter>>();
        try{
//            ErpSaleParameter parameter=parameterService.selectById(parameterId);
            List<ErpSaleParameter> carPage=parameterService.selectList(new EntityWrapper<ErpSaleParameter>().eq("pid",id));
            result.setCount(carPage.size());
            result.setData(carPage);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

}

